<?php
namespace app\common\controller;
use think\Loader;
use think\Controller;
use think\Db;

/**
* 后台公用基础控制器
* @author taigu
* @version 2017-9-22
*/
class AgentBaseController extends Controller {
	
    protected function _initialize() {
        parent::_initialize();
		$controller=request()->controller();
		$action=request()->action();
		$array_action=array("topay","fast_buy");
		if(strtolower($controller)=="shop"){
			if(!in_array($action, $array_action)){
				if (!session('agent_id')) {
            		$this->redirect('agent/login/index');
        		}
			}
		}else if($action=='hongb03' || $action=='hongb_page' || $action=='smfk' || $action=='xsmfk' || $action=='hongb_gq' || $action=='card' || $action=='chongzhi_card'){
		}else{
			 if (!session('agent_id')) {
            	$this->redirect('agent/login/index');
        	}
		}
       
        $this->assign('action',request()->action());
    }
	
	//图片上传
    public function upload(){
    	include_once ('././vendor/aliyun-oss-php-sdk/autoload.php');
		$files = $_POST["value"];  
	    $tmp = base64_decode($files);
	    $fn = time()."_".rand(100000, 999999) . ".jpg";
		$fp = '././public/uploads/image/'. $fn;
		$fp1 = '././public/uploads/image/'. $fn;
	    $res=file_put_contents( $fp, $tmp);
		$ossClient = new \OSS\OssClient('LTAIaqGtJ3JDXJvv', 'Q2kTcyepAHX0VOR44OtszVoyOKE8gl', 'oss-cn-shanghai.aliyuncs.com');
		try{
			$res=$ossClient->uploadFile("long3",$fn,$fp1);
			$src='https://long3.oss-cn-shanghai.aliyuncs.com/'.$fn;
			unlink($fp1);
			return json(["code"=>200,'url'=>$src]);
		} catch(OssException $e) {
			return json(["code"=>404,'msg'=>'上传错误']);
		} 
	} 
}
